package cn.patpang.core.framework.hibernate;

import java.io.Serializable;

/**
 * @Title BaseDaoView.java
 * @Author PangPX
 * @Data 2017年6月8日 下午2:50:56
 */
public class BDCondition implements Serializable {

	private static final long serialVersionUID = 1867017439905993431L;

	public final static String PLACEHOLDER_NAME = "_P_";
	public final static String PLACEHOLDER_VALUE = "_V_";

	public static enum K {

		/* AND */
		AND_EQ(" AND " + PLACEHOLDER_NAME + " = :" + PLACEHOLDER_VALUE), // AND-等于
		AND_NEQ(" AND " + PLACEHOLDER_NAME + " <> :" + PLACEHOLDER_VALUE), // AND-不等于
		AND_LT(" AND " + PLACEHOLDER_NAME + " < :" + PLACEHOLDER_VALUE), // AND-小于
		AND_LE(" AND " + PLACEHOLDER_NAME + " <= :" + PLACEHOLDER_VALUE), // AND-小于等于
		AND_GT(" AND " + PLACEHOLDER_NAME + " > :" + PLACEHOLDER_VALUE), // AND-大于
		AND_GE(" AND " + PLACEHOLDER_NAME + " >= :" + PLACEHOLDER_VALUE), // AND-大于等于
		AND_IN(" AND " + PLACEHOLDER_NAME + " IN (:" + PLACEHOLDER_VALUE + ")"), // AND-IN
		AND_NOTIN(" AND " + PLACEHOLDER_NAME + " NOT IN (:" + PLACEHOLDER_VALUE + ")"), // AND-NOT-IN
		AND_LIKE(" AND " + PLACEHOLDER_NAME + " LIKE :" + PLACEHOLDER_VALUE), // AND-LIKE
		AND_NOTLIKE(" AND " + PLACEHOLDER_NAME + " NOT LIKE :" + PLACEHOLDER_VALUE), // AND-NOT-LIKE
		AND_NULL(" AND " + PLACEHOLDER_NAME + " IS NULL "), // AND-IS-NULL
		AND_NOT_NULL(" AND " + PLACEHOLDER_NAME + " IS NOT NULL "), // AND-IS_NOT-NULL

		/* OR */
		OR_EQ(" OR " + PLACEHOLDER_NAME + " = :" + PLACEHOLDER_VALUE), // OR-等于
		OR_NEQ(" OR " + PLACEHOLDER_NAME + " <> :" + PLACEHOLDER_VALUE), // OR-不等于
		OR_LT(" OR " + PLACEHOLDER_NAME + " < :" + PLACEHOLDER_VALUE), // OR-小于
		OR_LE(" OR " + PLACEHOLDER_NAME + " <= :" + PLACEHOLDER_VALUE), // OR-小于等于
		OR_GT(" OR " + PLACEHOLDER_NAME + " > :" + PLACEHOLDER_VALUE), // OR-大于
		OR_GE(" OR " + PLACEHOLDER_NAME + " >= :" + PLACEHOLDER_VALUE), // OR-大于等于
		OR_IN(" OR " + PLACEHOLDER_NAME + " IN (:" + PLACEHOLDER_VALUE + ")"), // OR-IN
		OR_NOTIN(" OR " + PLACEHOLDER_NAME + " NOT IN (:" + PLACEHOLDER_VALUE + ")"), // OR-NOT-IN
		OR_LIKE(" OR " + PLACEHOLDER_NAME + " LIKE :" + PLACEHOLDER_VALUE), // OR-LIKE
		OR_NOTLIKE(" OR " + PLACEHOLDER_NAME + " NOT LIKE :" + PLACEHOLDER_VALUE), // OR-NOT-LIKE
		OR_NULL(" OR " + PLACEHOLDER_NAME + " IS NULL "), // OR-IS-NULL
		OR_NOT_NULL(" OR " + PLACEHOLDER_NAME + " IS NOT NULL "), // OR-IS_NOT-NULL

		/* SET */
		SET_EQ(" SET " + PLACEHOLDER_NAME + " = :" + PLACEHOLDER_VALUE),
		SET_NEXT(" , " + PLACEHOLDER_NAME + " = :" + PLACEHOLDER_VALUE),
		SET_NEXT_NULL(" , " + PLACEHOLDER_NAME + " = NULL"),

		/* WHERE */
		WHERE_EQ(" WHERE " + PLACEHOLDER_NAME + " = :" + PLACEHOLDER_VALUE),
		WHERE_IN(" WHERE " + PLACEHOLDER_NAME + " IN (:" + PLACEHOLDER_VALUE +")"),
		WHERE_LIKE(" WHERE " + PLACEHOLDER_NAME + " LIKE :" + PLACEHOLDER_VALUE);

		private String val;

		private K(String val) {
			this.val = val;
		}

		@Override
		public String toString() {
			return this.val;
		}

	}

	private K condition = K.AND_EQ;
	private String cName;
	private Object cVal;

	private BDCondition() {
	}

	private BDCondition(K condition, String cName, Object cVal) {
		this.condition = condition;
		this.cName = cName;
		this.cVal = cVal;
	}

	public static BDCondition set(K condition, String cName) {
		return new BDCondition(condition, cName, null);
	}

	public static BDCondition set(String cName, Object cVal) {
		return new BDCondition(K.AND_EQ, cName, cVal);
	}

	public static BDCondition set(K condition, String cName, Object cVal) {
		return new BDCondition(condition, cName, cVal);
	}

	public K getCondition() {
		return condition;
	}

	public String getcName() {
		return cName;
	}

	public Object getcVal() {
		return cVal;
	}

}
